<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('月评价结果列表')"/>
</head>
<style>
    .layui-table-cell {
        height: auto !important;
        line-height: 34px !important;
    }
    th .layui-table-cell {
        font-size: 12px !important;
    }
    .layui-table td, .layui-table th {
        font-size: 12px !important;
    }


</style>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">排名年月</label>
                <div class="layui-input-inline">
                    <input type="text" name="taskMonth" placeholder="" class="layui-input" id="taskMonth">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit
                        lay-filter="monthResult-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="monthResult-table" lay-filter="monthResult-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="monthResult-toolbar">
    <button shiro:hasPermission="gen:monthResult:add" class="pear-btn pear-btn-primary pear-btn-md"
            lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
    <button shiro:hasPermission="gen:monthResult:remove" class="pear-btn pear-btn-danger pear-btn-md"
            lay-event="batchRemove">
        <i class="layui-icon layui-icon-delete"></i>
        删除
    </button>
</script>

<script type="text/html" id="monthResult-bar">
    <button shiro:hasPermission="gen:monthResult:edit" class="pear-btn pear-btn-primary pear-btn-sm"
            lay-event="edit" title="修改"><i class="layui-icon layui-icon-edit"></i>
    </button>

    <button shiro:hasPermission="gen:monthResult:remove" class="pear-btn pear-btn-danger pear-btn-sm"
            lay-event="remove" title="删除"><i class="layui-icon layui-icon-delete"></i>
    </button>
</script>


<script type="text/html" id="monthResult-type">
    {{#if (d.dataState == '0') { }}
    <span class="layui-badge layui-bg-orange">开启</span>
    {{# }else if(d.dataState == '-1'){ }}
    <span class="layui-badge layui-bg-blue">关闭</span>
    {{# } }}
</script>

<th:block th:include="include :: footer"/>
<script th:inline="javascript" type="text/javascript">
    layui.use(['table', 'form', 'jquery'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        //默认查上个月数据
        var year = new Date().getFullYear()
        var month = new Date().getMonth();
        month = (month < 10 ? "0" + month : month);
        if (month == '00'){
            month = 12
            year = year - 1
        }
        //执行一个laydate实例
        laydate.render({
            elem: '#taskMonth' //指定元素
            ,type: 'month'
            // ,value: new Date()
            ,value: year + "-" + month
        })

        var MODULE_PATH = rootPath + "/MonthResultController/";
        var cols = [
            [
                // {type: 'checkbox'},

                {title: '排名', field: 'finalrank', align: 'center', width: 80},

                {title: '任务年月', field: 'taskMonth', align: 'center', width: 80},

                {title: '供电所名称', field: 'supplyName', align: 'center', width: 150},

                // {title: '所属分公司', field: 'orgnizationName', align: 'center', width: 220},

                {
                    field: 'star', title: '供电所星级', align: 'center', width: 120 ,templet: function (res) {
                        if (res.star == '1') {
                            return '一星';
                        } else if (res.star == '2') {
                            return '二星';
                        } else if (res.star == '3') {
                            return '三星';
                        } else if (res.star == '4') {
                            return '四星';
                        } else if (res.star == '5') {
                            return '五星';
                        } else {
                            return '';
                        }
                    }
                },

                {
                    title: '一、营销服务<br/>（20%）', field: 'yingxiaoScore', align: 'center', width: 120, templet: function (res) {
                        return redline(res.yingxiaoScore, res.star)
                    }
                },

                {
                    title: '二、运维抢修<br/>（20%）', field: 'yunjianScore', align: 'center', width: 120, templet: function (res) {
                        return redline(res.yunjianScore, res.star)
                    }
                },

                {
                    title: '三、安全管理<br/>（15%）', field: 'anquanScore', align: 'center', width: 120, templet: function (res) {
                        return redline(res.anquanScore, res.star)
                    }
                },

                {
                    title: '四、党建及<br/>队伍建设<br/>（15%）', field: 'dangjianScore', align: 'center', width: 130, templet: function (res) {
                        return redline(res.dangjianScore, res.star)
                    }
                },

                {
                    title: '五、数字化转型<br/>（10%）', field: 'shuzihuaScore', align: 'center', width: 130, templet: function (res) {
                        return redline(res.shuzihuaScore, res.star)
                    }
                },

                {
                    title: '六、发展规划<br/>（10%）', field: 'fazhanScore', align: 'center', width: 120, templet: function (res) {
                        return redline(res.fazhanScore, res.star)
                    }
                },

                {
                    title: '七、“五小”建设<br/>及基础保障<br/>（10%）', field: 'wuxiaoScore', align: 'center', width: 130, templet: function (res) {
                        return redline(res.wuxiaoScore, res.star)
                    }
                },

                {title: '总得分<br/>(未加权)', field: 'totalMark', align: 'center', width: 100},

                {title: '总得分<br/>(权重计算)', field: 'totalScore', align: 'center', width: 100},

                {
                    field: 'isNeccessary', title: '必备条件<br/>是否合格', align: 'center', width: 100, templet: function (res) {
                        if (res.isNeccessary == '0') {
                            return '<div style="background-color:#ff7777; width: 100%; height: 100%;"><a class=""style="color:#fff">否</a></div>';
                        } else if (res.isNeccessary == '1') {
                            return '是';
                        } else if (res.isNeccessary == '2') {
                            return '结果上报中';
                        }
                    }
                },

                // {
                //     field: 'isIssue', title: '结果是否发布', align: 'center', width: 150, templet: function (res) {
                //         if (res.isIssue == '0') {
                //             return '否';
                //         } else if (res.isIssue == '1') {
                //             return '是';
                //         } else if (res.isIssue == '2') {
                //             return '结果上报中';
                //         }
                //     }
                // },


                // {title: '操作', toolbar: '#monthResult-bar', align: 'center', width: 200}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#monthResult-table',
            url: MODULE_PATH + 'list',
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#monthResult-toolbar',
            limit:80,
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }],
            where: {'taskMonth': year + "-" + month}
        });

        //table图标事件绑定
        table.on('tool(monthResult-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(monthResult-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        //查询按钮绑定
        form.on('submit(monthResult-query)', function (data) {
            table.reload('monthResult-table', {where: data.field})
            return false;
        });


        //添加
        window.add = function () {
            layer.open({
                type: 2,
                title: '新增',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'add'
            });
        }
        //修改
        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'edit/' + obj.data['id']
            });
        }
        //删除
        window.remove = function (obj) {
            layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //批量删除
        window.batchRemove = function (obj) {
            var data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            var ids = "";
            for (var i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('monthResult-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        // 定义函数
        function redline(score, star) {
            console.log(score);
            var target = '';
            if (star == 5) {
                target = 90
            } else if (star == 4) {
                target = 85
            } else if (star == 3) {
                target = 80
            }
            if (score !== null && score !== "" && score !== "null") {
                if (score < target) {
                    return '<div style="background-color:#ff7777; width: 100%; height: 100%;"><a class=""style="color:#fff">' + score + '</a></div>';
                } else {
                    return score;
                }
            } else {
                return "";
            }
        }

        //刷新按钮
        window.refresh = function () {
            table.reload('monthResult-table');
        }
    })
</script>
</html>